/*************************************************************************
	> File Name: 1.getopt.c
	> Author: WangYiFei
	> Mail: 824537320@qq.com
	> Created Time: Sat 02 Jan 2021 05:20:52 PM CST
 ************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char **argv) {
    int opt;
    while ( (opt = getopt(argc, argv, "alm:o::")) != -1 ) {
        switch (opt) {
            case 'a':
                printf("a found!\n");
                break;
            case 'l':
                printf("b found!\n");
                break;
            case 'm':
                printf("m found!\n");
                printf("msg = %s\n", optarg);
                break;
            case 'o':
                printf("o found!\n");
                printf("opt = %s\n", optarg);
                break;
            default:
                fprintf(stderr, "Usage : %s -al\n", argv[0]);
                exit(1);
        }
    }

    return 0;
}
